﻿namespace OnWork.DataCenter.BLL.Base.Dto
{
    /// <summary>
    /// 数据库查询通用返回对象
    /// </summary>
    public class SQLReturn<T>
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 项目
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        ///  总数
        /// </summary>
        public int Total { get; set; } = 0;

        /// <summary>
        /// 返回信息
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 查询列表成功
        /// </summary>
        /// <param name="rows">添加的数量</param>
        /// <param name="msg">成功信息!</param>
        /// <returns></returns>
        public static SQLReturn<List<T>> QueryListSuccess(List<T> items, int total, string content = "获取成功!")
        {
            return new SQLReturn<List<T>>() { Content = content, Data = items, Total = total, IsSuccess = true };
        }
    }

    /// <summary>
    /// 返回通用的sql 查询
    /// </summary>
    public class SQLReturn
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 返回信息的标头
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 返回信息内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 返回执行的总数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 添加成功
        /// </summary>
        /// <param name="total">完成的数量</param>
        /// <param name="content">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static SQLReturn AddSuccess(int total = 1, string content = "添加数据成功!", string title = "添加数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = true, Title = title, Total = total };
        }

        /// <summary>
        /// 添加失败
        /// </summary>
        /// <param name="content">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static SQLReturn AddError(string content = "添加数据失败!", string title = "添加数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = false, Title = title, Total = 0 };
        }

        /// <summary>
        /// 删除成功
        /// </summary>
        /// <param name="total">完成的数量</param>
        /// <param name="content">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static SQLReturn DelSuccess(int total = 1, string content = "删除数据成功!", string title = "删除数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = true, Title = title, Total = total };
        }

        /// <summary>
        /// 删除失败
        /// </summary>
        /// <param name="rows">添加的数量</param>
        /// <param name="msg">成功信息!</param>
        /// <returns></returns>
        public static SQLReturn DelError(string content = "添加数据失败!", string title = "添加数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = false, Title = title, Total = 0 };
        }

        /// <summary>
        /// 更新成功
        /// </summary>
        /// <param name="total">完成的数量</param>
        /// <param name="content">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static SQLReturn UpdateSuccess(int total = 1, string content = "修改数据成功!", string title = "修改数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = true, Title = title, Total = total };
        }

        /// <summary>
        /// 更新失败
        /// </summary>
        /// <param name="content">消息内容</param>
        /// <param name="title">返回消息标题</param>
        /// <returns></returns>
        public static SQLReturn UpdateError(string content = "修改数据失败!", string title = "修改数据")
        {
            return new SQLReturn() { Content = content, IsSuccess = false, Title = title, Total = 0 };
        }
    }
}